<%@page import="beans.ClassBean"%>
<%@page import="dao.MngClass"%>
<%@page import="dao.CheckAccount"%>
<%@page import="beans.Assignment"%>
<%@page import="dao.MngAssignment"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@page import="java.util.List"%>

<html>
    <head>       
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Show Assignment Page</title>
        <style>                        
            table, th, td {
                border: 1px solid #619702;
                border-collapse: collapse;
                width:100% ;
            }
            th, td {
                padding: 5px;
                width: 100px;
            }
            th {
                text-align: center;
            }
        </style>
    </head>
    <body>   
        <h2>List Assignment</h2>
        <%
            MngClass mngClass = new MngClass();
            CheckAccount ck = new CheckAccount();
            MngAssignment mngAssign = new MngAssignment();
            HttpSession session_ass = request.getSession();
            String acc_id_assign = session_ass.getAttribute("acc_id").toString();
            List<Assignment> listAssign = null;
            if (request.getAttribute("class_id") == null || request.getAttribute("class_id").equals("")) {
                listAssign = mngAssign.showAssignByAccount(acc_id_assign);
            } else {
                listAssign = mngAssign.showAssignByAccountAndClass(acc_id_assign, request.getAttribute("class_id").toString());
            }
            if (request.getAttribute("msg") != null) {
        %>
        <font color="green" > <%= request.getAttribute("msg")%> </font><br><br>
        <% }  
        if (request.getAttribute("error") != null) {
        %>
        <font color="red" > <%= request.getAttribute("error")%> </font>
        <%
            }
        %>     
        <table>             
            <tr>              
                    <%
                        if (request.getAttribute("class_id") == null || request.getAttribute("class_id").equals("")) {
                    %>
                <th>Class</th>
                    <%
                        }
                    %>
                <th>Assignment Name</th>                
                <th>Create Date</th>
                <th>Finish Date</th>                
                <th>Assignment</th>     
                <th>Finish Assignment</th>                   
                <th>Mark</th>                       
            </tr> 
            <%  for (Assignment assign : listAssign) {
                    if (assign.getMark() == null) {
                        assign.setMark("");
                    }
                    if (assign.getCreate_date() == null) {
                        assign.setCreate_date("");
                    }
                    if (assign.getFile_ass() == null) {
                        assign.setFile_ass("");
                    }
                    if (assign.getFile_finishass() == null) {
                        assign.setFile_finishass("");
                    }
                    if (assign.getFinish_date() == null) {
                        assign.setFinish_date("");
                    }
            %>
            <tr>                    
                    <%
                        if (request.getAttribute("class_id") == null || request.getAttribute("class_id").equals("")) {
                    %>
                <th><%= mngClass.getClassName(assign.getClass_id())%></th>
                    <%
                        }
                    %>
                <th><%= assign.getAssign_name()%></th>                
                <th><%= assign.getCreate_date()%></th>
                <th><%= assign.getFinish_date()%></th>                              
                <th>
                    <% if ((assign.getFile_ass() != null) && (!assign.getFile_ass().equals(""))) { //download assignment
                            String link_download_ass = "downloadAssign?file_name=" + assign.getFile_ass();
                    %>
                    <a href="<%= link_download_ass%>">Download</a>
                    <%
                        }
                    %>
                </th>
                <th>
                    <%  //upload finish assignment
                        if ((assign.getFile_finishass() != null) && !assign.getFile_finishass().equals("")) {
                    %>         
                    File Finish Assignment : <%= assign.getFile_finishass()%>        
                    <% } else {%>
            <form action="uploadFinishAssign" method="post" enctype="multipart/form-data">
                <input type="hidden" name="assign_id" value="<%= assign.getAssign_id()%>">   
                <%if (request.getAttribute("class_id") != null && !request.getAttribute("class_id").equals("")) {
                %>
                <input type="hidden" name="class_id" value="<%= request.getAttribute("class_id")%>"> 
                <%
                    }
                %>
                <input type="file" name="file" />
                <input type="submit" value="Upload" />
            </form>        
            <% }%>
        </th>   
        <th>
            <%= assign.getMark()%>
        </th>
    </tr>   
    <%
        }%>
</table>
</body>
</html>
